/**
 * Created by hdr on 17/8/17.
 */
import MeasureItem from "./MeasureItem";
import Calc from "./Calc";
import UI from "./UI";
import DateUtils from "../utils/DateUtils";

const STAND_LEVEL = 0

export default class BodyAgeReport {

  static isEnable(measure) {
    return true //measure.origin.bodyage_flag && measure.origin.bodyage_flag === 1
  }

  static build(measure) {
    const value = measure.bodyAge
    if (!value || value == 0) {
      return null;
    }
    const item = new MeasureItem()
    const realAge = DateUtils.getAge(measure.birthday, measure.time)

    const boundaries = [realAge]

    const level = Calc.calcLevel(value, boundaries, STAND_LEVEL)

    const isStand = value <= realAge

    item.name = "体年龄"
    item.value = value
    item.isStand = isStand
    item.unit = "岁"
    item.bar = [UI.color.report_stand, UI.color.report_no_stand]
    item.showBar = false
    item.levelNames = ["达标", "不达标"]
    item.desc = "理想的体内年龄＝实际年龄　*　２ / ３，你还有年轻空间，加油！"
    item.level = level
    item.icon = 'report_bodyage.png'
    item.levelName = item.levelNames[item.level]
    item.levelColor = item.bar[item.level]

    if (!isStand) {
      item.offset = value - realAge
    }

    return item
  }

}



// WEBPACK FOOTER //
// ./src/report/BodyAge.js
